package com.qupai.lib_base.utils;

import static com.qupai.lib_base.app.BaseApplication.psaApp;

import android.graphics.Bitmap;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.StateListDrawable;
import android.widget.RadioButton;

public class SelectorUtils {
    /**
     * 创建Selector背景资源文件
     *
     * @param unchecked 非确认时候的资源文件
     * @param checked   确认时候的资源文件
     * @return selector
     */
    private StateListDrawable createDrawableSelector(Drawable unchecked, Drawable checked) {
        StateListDrawable stateList = new StateListDrawable();
        int statePressed = android.R.attr.state_pressed;
        int stateChecked = android.R.attr.state_checked;
        int stateFocused = android.R.attr.state_focused;
        stateList.addState(new int[]{stateChecked}, checked);
        stateList.addState(new int[]{statePressed}, checked);
        stateList.addState(new int[]{stateFocused}, checked);
        stateList.addState(new int[]{}, unchecked);
        return stateList;
    }

    /**
     * 根据bitmap位图文件生成selector
     *
     * @param bitmapDefault 默认图
     * @param bitmapChecked 选择图
     */

    private void createButtonSelector(Bitmap bitmapDefault, Bitmap bitmapChecked, RadioButton radioButton) {
        BitmapDrawable drawableDefault = new BitmapDrawable(psaApp.getResources(), bitmapDefault);
        BitmapDrawable drawableChecked = new BitmapDrawable(psaApp.getResources(), bitmapChecked);
        Drawable drawable = createDrawableSelector(drawableDefault, drawableChecked);
        drawable.setBounds(0, 0, 0, 0);
        radioButton.setCompoundDrawables(null, drawable, null, null);
    }


}
